@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        短信管理
        <small>短信任务列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/message">短信管理</a>></li>
        <li class="active">短信任务列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
        <?php //dd($message); ?>
            {{--<div class="box box-primary ">--}}
                {{--<div class="box-body table-responsive">--}}
                    {{--<a href="{{route('admin.ad_position.create')}}" class="btn btn-success"><i class="icon glyphicon glyphicon-plus"></i>添加</a>--}}

                    {{--{!! Form::model(@$adpos,array('route' => 'admin.ad_position.index','method' => 'get','class'=>'form-search form-inline pull-right')) !!}--}}
                    {{--<div class="form-group">--}}
                        {{--{!! Form::text('position_name',$search['position_name'],['class'=>'form-control','placeholder'=>'广告位名称'])!!}--}}
                    {{--</div>--}}
                    {{--<button type="submit" class="btn btn-primary">搜索</button>--}}
                    {{--<button type="button" onclick="window.location.href='/admin/ad_position'" class="btn btn-default">重置</button>--}}
                    {{--{!! Form::close() !!}--}}
                {{--</div>--}}
            {{--</div>--}}
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">短信任务列表</h3>
                    <div class="box-tools">
                        <a href="{{Route('admin.message.create')}}" type="button" class="btn  btn-box-tool"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>
                    </div>
                </div>
                <!-- /.box-header -->
                <?php $send_object_arr = ['0'=>'所以用户','1'=>'近三个月登录用户','2'=>'邮箱认证用户']?>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th>ID</th>
                            <th>短信内容</th>
                            <th>发送对象</th>
                            <th>创建时间</th>
                            <th style="width: 300px;">操作</th>
                        </tr>
                        @foreach($message as $item)
                            <tr>
                                <td>{{$item->id}}</td>
                                <td>{{$item->content}}</td>
                                <td>{{$send_object_arr[$item->send_object]}}</td>
                                <td>{{$item->create_time}}</td>

                                <td>
                                    <a data-id="{{$item->id}}" data-content="{{$item->content}}" data-object="{{$item->send_object}}" type="button" class="btn  btn btn-primary btn-xs btn-send"><i class="icon glyphicon glyphicon-hand-right"></i> 发送</a>
                                    <a href="{{Route('admin.message.edit',$item->id)}}" type="button" class="btn  btn-default btn-xs"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>

                                    <button type="button" class="btn  btn-danger btn-xs"  data-toggle="modal" data-target="#modal{{$item->id}}"><i class="icon  glyphicon glyphicon-remove"></i> 删除</button>

                                    <div id="modal{{$item->id}}" class="modal fade">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title">删除警告:</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>确认要删除[{{$item->content}}]吗?</p>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                    <button itemid="{{$item->id}}" class="btn btn-danger btn-danger01">删除</button>
                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

                                </td>

                            </tr>
                        @endforeach
                    </table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="pull-right no-margin-pager">
                        {!! $message->render() !!}
                    </div>
                </div>
            </div>
            <!-- /.box -->


        </div>
    </div>



</section>
<!-- /.content -->
<script>
        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid");
            //alert("dsaff");
            if(!id) return false;
            $.ajax({
                url:'/admin/message/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){

                    if(result.status){
                        $('#del_alert').modal();
                        $("#ok").hide();
                        $("#no").show();
                        $("#message_content").html(result.info);
                    }else{
                        window.location.reload();
                    }
                }
            });
        });
</script>
<script>
    $('.btn-send').on('click',function(){
    var btn=$(this), id = btn.data('id'), content = btn.data('content'), object = btn.data('object');
    //alert(content);
        console.log('11');
        $.ajax({
            url:'/admin/message/send'+"?"+Math.random(),
            type:'post',
            data:{id:id,content:content,object:object,'_token':'{{csrf_token()}}'},
            dataType:"json",
            success:function(result){
                if(result.status){
                    window.location.reload();
                }
            }

        });
    });
</script>
@endsection